package com.git_taoxina.homework.test2;

public class Threads {
    private int tickets;

    public Threads() {
    }

    public Threads(int tickets) {
        this.tickets = tickets;
    }

    public void getTicket(int tickets) {
        String name = Thread.currentThread().getName();
        synchronized (this) {
            if (this.tickets > 0) {
                System.out.println(name + "卖了一张票");
                this.tickets--;
                System.out.println("还剩下" + this.tickets + "张票");
            } else {
                System.out.println("没票了！");
            }
        }
    }


    public int getTickets() {
        return tickets;
    }

    public void setTickets(int tickets) {
        this.tickets = tickets;
    }
}
